export let KEY='goodsData';

export let valueObj={goodsid:0,count:0};

export function setItem(value) {
  let jsonString=localStorage.getItem(KEY);
  jsonString=jsonString || '[]';
  let arr=JSON.parse(jsonString);
  arr.push(value);
  localStorage.setItem(KEY,JSON.stringify(arr))
}


export function getItem(value) {
let jsonString=localStorage.getItem(KEY);
jsonString=jsonString || '[]';
return JSON.parse(jsonString);
}


export function removeItem() {

}

export function getgoodsObj() {
  let arr=getItem();
  let resObj={};
  for(let i=0;i<arr.length;i++){
    let item=arr[i];
    if(!resObj[item.goodsid]){
      resObj[item.goodsid]=item.count;
    }else{
      resObj[item.goodsid]=resObj[item.goodsid]+item.count
    }
  }
}
